﻿package control
{
    import com.core.*;
    import com.sh.game.global.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;

    public class NewTipsControl extends Control
    {
        private var alltips:Dictionary;
        private var currentTips:Object;
        private var curdata:Object;
        private var armsPoint:Point;

        public function NewTipsControl(param1:Object) : void
        {
            this.alltips = new Dictionary();
            super(param1);
            return;
        }// end function

        override protected function initView() : void
        {
            this.alltips["skilltips"] = (this.target as Sprite).getChildByName("skilltips");
            this.alltips["armtips"] = (this.target as Sprite).getChildByName("armtips");
            this.alltips["tooltips"] = (this.target as Sprite).getChildByName("tooltips");
            this.alltips["contrastArmtips"] = (this.target as Sprite).getChildByName("contrastArmtips");
            this.alltips["fstips1"] = (this.target as Sprite).getChildByName("fstips1");
            this.alltips["bstips"] = (this.target as Sprite).getChildByName("bstips");
            this.alltips["tasktips"] = (this.target as Sprite).getChildByName("tasktips");
            this.alltips["hdtips"] = (this.target as Sprite).getChildByName("hdtips");
            this.alltips["taskctips"] = (this.target as Sprite).getChildByName("taskctips");
            this.alltips["paotips"] = (this.target as Sprite).getChildByName("paotips");
            this.alltips["rankingTips"] = (this.target as Sprite).getChildByName("rankingTips");
            this.alltips["xianshiTips"] = (this.target as Sprite).getChildByName("xianshiTips");
            this.alltips["ringTips"] = (this.target as Sprite).getChildByName("ringTips");
            this.alltips["fashiontips"] = (this.target as Sprite).getChildByName("fashiontips");
            this.alltips["froomtips"] = (this.target as Sprite).getChildByName("froomtips");
            this.alltips["superTips"] = (this.target as Sprite).getChildByName("superTips");
            this.alltips["wingskilltips"] = (this.target as Sprite).getChildByName("wingskilltips");
            this.alltips["horseskilltips"] = (this.target as Sprite).getChildByName("horseskilltips");
            this.alltips["goodsTips"] = (this.target as Sprite).getChildByName("goodsTips");
            this.alltips["specialTips"] = (this.target as Sprite).getChildByName("specialTips");
            while ((this.target as Sprite).numChildren > 0)
            {
                
                (this.target as Sprite).removeChildAt(0);
            }
            return;
        }// end function

        override public function update(param1:Obproxy, param2:ProxyChange) : void
        {
            var _loc_5:Object = null;
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_9:Object = null;
            var _loc_3:* = new Object();
            var _loc_4:* = new Point();
            if (param1.getName() == "tips")
            {
                if (param2.property == "state")
                {
                    if (param2.newvalue == "close")
                    {
                        this.closeTips();
                    }
                }
                else if (param2.property == "skill")
                {
                    this.showTips("skilltips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "tool")
                {
                    this.showTips("tooltips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "xianshi")
                {
                    this.showTips("xianshiTips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "task")
                {
                    this.showTips("tasktips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "huodong")
                {
                    this.showTips("hdtips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "taskc")
                {
                    this.showTips("taskctips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "pao")
                {
                    this.showTips("paotips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "arm")
                {
                    if (param2.newvalue.data is Array)
                    {
                        _loc_5 = param2.newvalue.data[0];
                    }
                    else
                    {
                        _loc_5 = param2.newvalue.data;
                    }
                    if (_loc_5.itemid >= 350001 && _loc_5.itemid <= 350010 || _loc_5.itemid == 1411150)
                    {
                        this.showTips("bstips", _loc_5, param2.newvalue.p);
                    }
                    else
                    {
                        this.showTips("armtips", param2.newvalue.data, param2.newvalue.p);
                    }
                    _loc_6 = _loc_5.cls;
                    _loc_7 = ModelProxy.getValue("data", "user");
                    if (_loc_7.career != _loc_5.career && _loc_5.career != 0)
                    {
                        return;
                    }
                    _loc_8 = ModelProxy.getValue("data", "arms");
                    if (_loc_8[_loc_6])
                    {
                        if (_loc_8[_loc_6 + 7] && _loc_8[_loc_6 + 7].id == _loc_5.id)
                        {
                            return;
                        }
                        if (_loc_8[_loc_6].itemid != _loc_5.itemid)
                        {
                            _loc_8[_loc_6].wear = 1;
                            if (int(_loc_8[_loc_6].itemid) <= 0)
                            {
                                return;
                            }
                            this.fusushow(_loc_8[_loc_6]);
                        }
                    }
                }
                else if (param2.property == "fstips")
                {
                    this.fusushow(param2.newvalue);
                }
                else if (param2.property == "updatePao")
                {
                    _loc_9 = this.alltips["paotips"];
                    if (_loc_9.visible)
                    {
                        _loc_9.data = param2.newvalue;
                    }
                }
                else if (param2.property == "rank")
                {
                    this.showTips("rankingTips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "froomtips")
                {
                    this.showTips("froomtips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "superTips")
                {
                    this.showTips("superTips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "wingskilltips")
                {
                    this.showTips("wingskilltips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "horseskilltips")
                {
                    this.showTips("horseskilltips", param2.newvalue.data, param2.newvalue.p);
                }
                else if (param2.property == "specialTips")
                {
                    this.showTips("specialTips", param2.newvalue.data, param2.newvalue.p);
                }
            }
            return;
        }// end function

        private function showTips(param1:String, param2:Object, param3:Point, param4:Object = null) : void
        {
            if (this.currentTips || param2.hasOwnProperty("cfg") && int(param2.cfg.taskgroupid) == 99)
            {
                return;
            }
            this.curdata = param2;
            this.closeTips();
            var _loc_5:* = this.alltips[param1];
            this.alltips[param1].data = this.curdata;
            this.target.addChild(_loc_5);
            _loc_5.x = param3.x + 10;
            _loc_5.y = param3.y + 5;
            this.currentTips = _loc_5;
            if (param4)
            {
                this.currentTips.setwidth(int(param4));
            }
            var _loc_6:* = GlobalLayer.instance.flashStage;
            if (_loc_5.width + _loc_5.x > _loc_6.stageWidth)
            {
                _loc_5.x = _loc_6.stageWidth - 40 - _loc_5.width;
            }
            if (_loc_5.height + _loc_5.y > _loc_6.stageHeight - 40)
            {
                _loc_5.y = _loc_6.stageHeight - 40 - _loc_5.height;
            }
            if (_loc_5.y < 0)
            {
                _loc_5.y = 0;
            }
            return;
        }// end function

        private function fusushow(param1:Object) : void
        {
            var _loc_2:String = "";
            if (param1.itemid >= 350001 && param1.itemid <= 350010 || param1.itemid == 202109)
            {
                _loc_2 = "fstips1";
            }
            else
            {
                _loc_2 = "contrastArmtips";
            }
            var _loc_3:* = this.alltips[_loc_2];
            _loc_3.data = param1;
            this.target.addChild(_loc_3);
            if (this.currentTips)
            {
                _loc_3.x = this.currentTips.x + this.currentTips.width;
            }
            _loc_3.y = this.currentTips.y;
            var _loc_4:* = GlobalLayer.instance.flashStage;
            if (_loc_3.x + _loc_3.width > _loc_4.stageWidth)
            {
                _loc_3.x = _loc_4.stageWidth - 40 - _loc_3.width;
                this.currentTips.x = _loc_3.x - this.currentTips.width;
            }
            if (_loc_3.height + _loc_3.y > _loc_4.stageHeight - 40 || this.currentTips.height + this.currentTips.y > _loc_4.stageHeight - 40)
            {
                if (_loc_3.height > this.currentTips.height)
                {
                    this.currentTips.y = _loc_4.stageHeight - 40 - _loc_3.height;
                }
                else
                {
                    this.currentTips.y = _loc_4.stageHeight - 40 - this.currentTips.height;
                }
                _loc_3.y = this.currentTips.y;
            }
            if (_loc_3.y < 0)
            {
                _loc_3.y = 0;
                this.currentTips.y = 0;
            }
            return;
        }// end function

        private function closeTips() : void
        {
            var _loc_1:Object = null;
            this.currentTips = null;
            for each (_loc_1 in this.alltips)
            {
                
                if (_loc_1 && _loc_1.parent)
                {
                    _loc_1.parent.removeChild(_loc_1);
                }
            }
            return;
        }// end function

    }
}
